package com.leyou.statis.controller;

import com.leyou.common.bean.Result;
import com.leyou.statis.dto.PolymerDTO;
import com.leyou.statis.dto.StatisVO;
import com.leyou.statis.service.StatisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zqq
 * @ClassName StatisController
 * @Description
 * @date 2020/4/6-17:33
 */
@RestController
@Api(value = "StatisController",description = "统计接口")
@RequestMapping("polymer")
public class StatisController {

    @Autowired
    private StatisService statisService;

    @PostMapping("type")
    @ApiOperation(value = "根据条件聚合一个月的数据", notes = "根据条件聚合一个月的数据")
    public Result<List<StatisVO>> queryStatisByType(@RequestBody PolymerDTO dto) {
        return this.statisService.queryStatisByDto(dto);
    }

    @GetMapping("quarter/{year}")
    @ApiOperation(value = "按照季度聚合", notes = "按照季度聚合")
    public Result<List<StatisVO>> queryStatisByQuarter(@ApiParam(name = "year",value = "年",required = true) @PathVariable(value = "year") String year) {
        return this.statisService.queryStatisByQuarter(year);
    }

    @GetMapping("month/{year}")
    @ApiOperation(value = "按照一年的12个月聚合", notes = "按照一年的12个月聚合")
    public Result<List<StatisVO>> queryStatisByMonth(@ApiParam(name = "year",value = "年",required = true) @PathVariable(value = "year") String year) {
        return this.statisService.queryStatisByMonth(year);
    }

    @GetMapping("years")
    @ApiOperation(value = "获取最新3年的数据", notes = "获取最新3年的数据")
    public Result<Map<Integer,List<StatisVO>>> queryStatisByYears() {
        return this.statisService.queryStatisByYears();
    }

}
